package com.kgc.cgconsumer.Controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.cgconsumer.service.CGConServ;
import com.kgc.cgconsumer.service.CGTHConsumerService;
import com.kgc.cgconsumer.service.CgWorkFlowService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("CGTH")
public class CGTHController {
    private static Logger logger = LoggerFactory.getLogger(CGTHController.class);

    @Resource
    private CGTHConsumerService cgthConsumerService;

    @Resource
    private CGConServ cgConServ;

    @Resource
    private CgWorkFlowService cgWorkFlowService;

    @RequestMapping("getPage")
    public ResponseMsg getPage(@RequestBody Map<String,Object> map) {
//        ResponseMsg responseMsg = cgthConsumerService.getCGTHPage(map);
        ResponseMsg responseMsg = cgthConsumerService.getCGTHPage(map);
        return responseMsg;
    }

    @RequestMapping("delCGTH")
    public ResponseMsg delCGTH(String code) {
        ResponseMsg responseMsg = cgConServ.del("cg_fcgth" , code);
        return responseMsg;
    }
    @RequestMapping("addCGTH")
    public ResponseMsg addCGTH(@RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = cgthConsumerService.addCGTH(map);
        Map<String,Object> variables = new HashMap<>();
        variables.put("code",responseMsg.getData());//单据编号
        variables.put("type",map.get("type"));//流程类型
        //创建一个流程实例
        com.kgc.activiti.util.ResponseMsg res = cgWorkFlowService.startProcess(variables);
        if (!"200".equals(res.getCode())){
            responseMsg.setCode(res.getCode());
        }
        return responseMsg;
    }
    @RequestMapping("getCGTH")
    public ResponseMsg getCGTH(@RequestBody Map<String , Object> map) {
        ResponseMsg responseMsg = cgthConsumerService.getCGTH(map);
        return responseMsg;
    }
    @RequestMapping("modiCGTH")
    public ResponseMsg modiCGTH(@RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = cgthConsumerService.modiCGTH(map);
        return responseMsg;
    }


}
